<?php
use lib\dao\Dao;

class DaoReporte extends Dao{

	public function compraXEvento(\lib\model\Model $M, \lib\dao\query\Query $Q){

		$table = $this->getTable($M);
		$query = $Q->prepare($M)->query;

		$sql   = "SELECT e.nombre,if(sum(cantidad) is null,0,sum(cantidad)) as cantidad,if(sum(cantidad)*precio is null,0,sum(cantidad)*precio) as monto
                        FROM evento e 
				left join ticket t on(t.evento_id=e.id)
				left join compra c on(c.ticket_id=t.id)
				group by e.id";

		$binds = $Q->binds;
		$Dar   = $this->DataAccess->retrieve($sql, $binds);
		return $Dar->fetchAll();
	}

	public function compraXCategoria(\lib\model\Model $M, \lib\dao\query\Query $Q){

		$table = $this->getTable($M);
		$query = $Q->prepare($M)->query;

		$sql   = "SELECT ca.nombre,if(sum(cantidad) is null,0,sum(cantidad)) as cantidad
                        ,if(sum(cantidad)*precio is null,0,sum(cantidad)*precio) as monto 
                        FROM evento e 
					left join ticket t on(t.evento_id=e.id)
					left join compra c on(c.ticket_id=t.id)
					join categoria ca on(e.categoria_id=ca.id)
					group by e.categoria_id";

		$binds = $Q->binds;
		$Dar   = $this->DataAccess->retrieve($sql, $binds);
		return $Dar->fetchAll();
	}






	

}